package planit.controller.impl;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JOptionPane;

import planit.model.Model;
import planit.view.EditPersonDialog;

@SuppressWarnings("serial")
public class EditPersonController extends AbstractAction {
	private Model model;

	public EditPersonController(Model model) {
		this.model = model;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		EditPersonDialog dialog = (EditPersonDialog)this.getValue("EditPersonDialog");
		
		if (dialog.getPersonName().length() > 0) {
			model.getSchedule().getPerson(dialog.getPersonId())
			.setName(dialog.getPersonName());
			model.getSchedule().getPerson(dialog.getPersonId())
			.setEmailAddress(dialog.getPersonEmail());
			model.getSchedule().getPerson(dialog.getPersonId())
			.setPhoneNumber(dialog.getPersonPhone());
		} else {
			JOptionPane.showMessageDialog(null,
					"You have to enter the name of the person", "Error",
					JOptionPane.WARNING_MESSAGE);
		}
	}
}
